package com.mall.controller;


import com.mall.pojo.Category;
import com.mall.service.CategoryService;
import com.mall.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 简单案例 - 商品分类表 前端控制器
 * </p>
 *
 * @author 戴浩军
 * @since 2022-06-06
 */
@RestController
@RequestMapping("/categorys")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("id")
    public Msg addCategoryCount(@PathVariable Integer id){
        Category c = categoryService.getById(id);
        c.setId(c.getId()+1);
        categoryService.save(c);
        return Msg.success("添加了新的商品分类");
    }

    @GetMapping
    public Msg getAllCategory(){
        return Msg.success("查询全部的分类").add("all",categoryService.list());
    }


}

